package cn.zjyj.module.zjyj.controller.admin.riskidentify;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.zjyj.framework.common.common.pojo.PageResult;
import cn.zjyj.framework.common.common.pojo.CommonResult;

import static cn.zjyj.framework.common.common.pojo.CommonResult.success;

import cn.zjyj.framework.apilog.core.annotation.ApiAccessLog;
import static cn.zjyj.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.zjyj.module.zjyj.controller.admin.riskidentify.vo.*;
import cn.zjyj.module.zjyj.service.riskidentify.RiskIdentifyService;

@Tag(name = "管理后台 - 风险辨识主")
@RestController
@RequestMapping("/zjyj/risk-identify")
@Validated
public class RiskIdentifyController {

    @Resource
    private RiskIdentifyService riskIdentifyService;

    @PostMapping("/create")
    @Operation(summary = "创建风险辨识主")
    @PreAuthorize("@ss.hasPermission('zjyj:risk-identify:create')")
    public CommonResult<Long> createRiskIdentify(@Valid @RequestBody RiskIdentifySaveReqVO createReqVO) {
        return success(riskIdentifyService.createRiskIdentify(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新风险辨识主")
    @PreAuthorize("@ss.hasPermission('zjyj:risk-identify:update')")
    public CommonResult<Boolean> updateRiskIdentify(@Valid @RequestBody RiskIdentifySaveReqVO updateReqVO) {
        riskIdentifyService.updateRiskIdentify(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除风险辨识主")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('zjyj:risk-identify:delete')")
    public CommonResult<Boolean> deleteRiskIdentify(@RequestParam("id") Long id) {
        riskIdentifyService.deleteRiskIdentify(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除风险辨识主")
                @PreAuthorize("@ss.hasPermission('zjyj:risk-identify:delete')")
    public CommonResult<Boolean> deleteRiskIdentifyList(@RequestParam("ids") List<Long> ids) {
        riskIdentifyService.deleteRiskIdentifyListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得风险辨识主")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('zjyj:risk-identify:query')")
    public CommonResult<RiskIdentifyRespVO> getRiskIdentify(@RequestParam("id") Long id) {
        RiskIdentifyRespVO riskIdentify = riskIdentifyService.getRiskIdentify(id);
        return success(riskIdentify);
    }

    @GetMapping("/page")
    @Operation(summary = "获得风险辨识主分页")
    @PreAuthorize("@ss.hasPermission('zjyj:risk-identify:query')")
    public CommonResult<PageResult<RiskIdentifyRespVO>> getRiskIdentifyPage(@Valid RiskIdentifyPageReqVO pageReqVO) {
        return success(riskIdentifyService.getRiskIdentifyPage(pageReqVO));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出风险辨识主 Excel")
    @PreAuthorize("@ss.hasPermission('zjyj:risk-identify:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportRiskIdentifyExcel(@Valid RiskIdentifyPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        /*pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<RiskIdentifyDO> list = riskIdentifyService.getRiskIdentifyPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "风险辨识主.xls", "数据", RiskIdentifyRespVO.class,
                        BeanUtils.toBean(list, RiskIdentifyRespVO.class));*/
    }

    @GetMapping("/applyAssessment")
    public CommonResult<Boolean> applyAssessment(@RequestParam(name = "id") Long id) {
        riskIdentifyService.applyAssessment(id);
        return success(true);
    }

    @GetMapping("/applyRecord/page")
    @Operation(summary = "获得风险辨识主分页")
    public CommonResult<PageResult<RiskIdentifyApplyRecordRespVO>> getRiskIdentifyApplyRecordPage(@Valid RiskIdentifyApplyRecordPageReqVO pageReqVO) {
        return success(riskIdentifyService.getRiskIdentifyApplyRecordPage(pageReqVO));
    }


}